<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客正文</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_content.css">
    <link rel="stylesheet" href="editor.md/css/editormd.preview.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/tool.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="image/happy.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="login.html">登陆</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <div class="container-left">
            <div class="card">
                <h3></h3>
                <a href="#">gitee 地址</a>
                <div class="counter">
                    <span>文章</span>
                </div>
                <div class="counter">
                    <span class="total"></span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <div class="blog-content">
                <!-- 博客标题 -->
                <h3>我的第一篇博客</h3>
                <!-- 博客时间 -->
                <div  class="date">
                	点赞量：<span id="thumb"> </span>
                	&nbsp;&nbsp;&nbsp;&nbsp;
                    <span id="data">
                		2022-01-09
                	</span>
                	&nbsp;&nbsp;&nbsp;&nbsp;
                     访问量：<span id="rcount"></span>
                </div>
                <!-- 博客正文 -->
                <div id="editorDiv">

                </div>
                <hr />
                <!--评论区-->
               <div class="comment-container">
<!--                    <div class="name">krik</div>-->
<!--                    <div class="date">2023.02.02 9:08</div>-->
<!--                    <div class="content">kajscabksbxbaksjcbksdkb kjbsdkacnaudkbvkauecbaksdbcas</div>-->
               </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
            var editormd;
            function initEdit(md){
                editormd = editormd.markdownToHTML("editorDiv", {
                markdown : md, // Also, you can dynamic set Markdown text
                // htmlDecode : true,  // Enable / disable HTML tag encode.
                // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
                });
            }



            function getBlog(){
                var param=getURLParam("id");
                $.ajax({
                   url:"/art/getBlog",
                   method: "POST",
                   data: {
                      "id":param
                   } ,
                    success:function (result){
                       if(result.code == 200 && result.data!=null){
                           let art=result.data;
                           console.log(art);
                           let h3 = document.querySelector('.blog-content h3');
                           h3.innerHTML = art.title;
                           let divDate = document.querySelector('.blog-content .date');
                           divDate.innerHTML = art.updatetime;
                           editormd.markdownToHTML('editorDiv', {
                               markdown: art.content
                           });
                       }else{

                           alert(result.msg)
                       }
                    }
                });
            }
            getBlog();
            function getComment(){
                var id=getURLParam("id");
                $.ajax({
                   url:"/comment/getComment",
                   method: "POST",
                   data: {
                       "aid":id
                   },
                   success:function (result){
                        if(result.code == 200 && result.data != null){
                            let list=result.data;
                            let container=document.querySelector(".comment-container");
                            for(let comment of list){

                                let commentDiv=document.createElement('div');
                                commentDiv.className='comment';
                               let hr=document.createElement('hr');
                               commentDiv.appendChild(hr);
                                //姓名(作者id）
                                let nameDiv=document.createElement('div');
                                nameDiv.className='name';
                                nameDiv.innerHTML=comment.aid;
                                commentDiv.appendChild(nameDiv);
                                //时间
                                let dateDiv=document.createElement('div');
                                dateDiv.className='date';
                                dateDiv.innerHTML=comment.time;
                                commentDiv.appendChild(dateDiv);
                                //内容
                                let contentDiv=document.createElement('div');
                                contentDiv.className='content';
                                contentDiv.innerHTML=comment.content;
                                commentDiv.appendChild(contentDiv);
                                container.appendChild(commentDiv);
                            }
                        }else{
                            alert(result.msg)
                        }
                   }
                });
            }
            getComment();
            function getAuthuerInfo(){
                let aid=getURLParam("id");
                $.ajax({
                   url:"/user/getAuthurInfo" ,
                    method:"POST",
                    data:{
                       "aid":aid
                    },
                    success:function (result){
                       if(result.code == 200 && result.data != null){
                           var userinfo=result.data;
                           console.log(userinfo)
                           let h3=document.querySelector(".card h3");
                           h3.innerHTML=userinfo.username;
                           let count=document.querySelector(".card .counter .total");
                           count.innerHTML=userinfo.bcount;
                           let a=document.querySelector(".card a");
                           a.href=userinfo.useraddre;
                       }else{
                           alert(result.msg);
                       }
                    }
                });
            }
            getAuthuerInfo();
            // function func1(){
            //     var aid=getURLParam("id");
            //     $.ajax({
            //        url:"/user/photoUploadByArt" ,
            //         method:"GET",
            //         data:{
            //            "aid":aid
            //         }
            //     });
            // }
    </script> 
</body>

</html>